function action(event) {
    tweets_client[0].innerHTML = event.relatedNode.innerHTML;
}

function OnLoad () {
    var hypernode = __selectElements(document, "//hypernode")[0]; //seleziona l'hypernode locale
    var tweets_client = __selectElements(document, ".//div[@id='tweets_cl']")[0]; //seleziona div tweets del client
    var tweets_server = __selectElements(hypernode, ".//div[@class='tweet']"); //seleziona tweet remoti

    //Client registrato agli eventi di modifica del sottoalbero tweets_server del server
    __registerEventListener(hypernode, ".", "DOMNodeInserted", action);

    
    for (n in tweets_server){
        tweets_client.appendChild(tweets_server[n]);
    }
    
}

function AddTweet() {
    var msg = __selectElements(document, ".//textarea[@name='message']")[0];
    var hypernode = __selectElements(document, ".//hypernode")[0];
    var tweets = __selectElements(hypernode, ".")[0];
    
    var new_tweet = document.createElement("div");
    new_tweet.setAttribute("class","tweet");
    new_tweet.innerHTML = msg.value;
    
    tweets.insertBefore(new_tweet,tweets.firstChild);
    
    tweets.commit();
}